package com.qingyan.flink.datasource.mysql;

import lombok.Getter;
import org.apache.flink.connector.jdbc.catalog.MySqlCatalog;

/**
 * @author csp 2023-12-26
 */
@Getter
public class MySqlCatalogBuilder {
    private final ClassLoader classLoader = ClassLoader.getSystemClassLoader();
    private final String baseUrl = "jdbc:mysql://%s:%d";
    private String catalogName = "mysql-catalog";
    private String defaultDatabase;
    private String username;
    private String pwd;
    private String host;
    private int port = 3306;

    public  MySqlCatalogBuilder builder() {
        return new MySqlCatalogBuilder();
    }

    public MySqlCatalogBuilder host(String host){
        this.host = host;
        return this;
    }

    public MySqlCatalogBuilder port(int port){
        this.port = port;
        return this;
    }

    public MySqlCatalogBuilder database(String database){
        this.defaultDatabase = database;
        return this;
    }


    public MySqlCatalogBuilder username(String username){
        this.username = username;
        return this;
    }

    public MySqlCatalogBuilder catalog(String catalog){
        this.catalogName = catalog;
        return this;
    }

    public MySqlCatalogBuilder pwd(String pwd){
        this.pwd = pwd;
        return this;
    }

    public MySqlCatalog build() {
        return new MySqlCatalog(classLoader, catalogName, defaultDatabase, username, pwd, String.format(baseUrl, host, port));
    }

}

